// haha

//
function Show_Hidden(obj) {
    if (obj.style.display == "block") {
        obj.style.display = 'none';
    } else {
        obj.style.display = 'block';
    }
}
window.onload = function() {
        var olink = document.getElementById("username");
        var odiv = document.getElementById("dropdown-nav");
        olink.onclick = function() {
            Show_Hidden(odiv);
            return false;
        }
    }

    function userImg(){
        var imgObj = document.getElementById("userImg");
        var flag=(imgObj.getAttribute("src",2)=="images/icon1.png")
        imgObj.src=flag?"images/icon2.png":"images/icon1.png";
    }




//    分页
/**
 * Created by zxm on 2017/3/31.
 */
$.fn.extend({
    "initPage":function(listCount,currentPage,fun){
        var maxshowpageitem = $(this).attr("maxshowpageitem");
        if(maxshowpageitem!=null&&maxshowpageitem>0&&maxshowpageitem!=""){
            page.maxshowpageitem = maxshowpageitem;
        }
        var pagelistcount = $(this).attr("pagelistcount");
        if(pagelistcount!=null&&pagelistcount>0&&pagelistcount!=""){
            page.pagelistcount = pagelistcount;
        }

        var pageId = $(this).attr("id");
        page.pageId=pageId;
        if(listCount<0){
            listCount = 0;
        }
        if(currentPage<=0){
            currentPage=1;
        }
        page.setPageListCount(listCount,currentPage,fun);

    }
});
var  page = {
    "pageId":"",
    "maxshowpageitem":5,//最多显示的页码个数
    "pagelistcount":10,//每一页显示的内容条数
    /**
     * 初始化分页界面
     * @param listCount 列表总量
     */
    "initWithUl":function(listCount,currentPage){
        var pageCount = 1;
        if(listCount>=0){
            var pageCount = listCount%page.pagelistcount>0?parseInt(listCount/page.pagelistcount)+1:parseInt(listCount/page.pagelistcount);
        }
        var appendStr = page.getPageListModel(pageCount,currentPage);
        $("#"+page.pageId).html(appendStr);
    },
    /**
     * 设置列表总量和当前页码
     * @param listCount 列表总量
     * @param currentPage 当前页码
     */
    "setPageListCount":function(listCount,currentPage,fun){
        listCount = parseInt(listCount);
        currentPage = parseInt(currentPage);
        page.initWithUl(listCount,currentPage);
        page.initPageEvent(listCount,fun);
        fun(currentPage);
    },
    "initPageEvent":function(listCount,fun){
        $("#"+page.pageId +">li[class='pageItem']").on("click",function(){
            page.setPageListCount(listCount,$(this).attr("page-data"),fun);
        });
    },
    "getPageListModel":function(pageCount,currentPage){
        var prePage = currentPage-1;
        var nextPage = currentPage+1;
        var prePageClass ="pageItem";
        var nextPageClass = "pageItem";
        if(prePage<=0){
            prePageClass="pageItemDisable";
        }
        if(nextPage>pageCount){
            nextPageClass="pageItemDisable";
        }
        var appendStr ="";
        appendStr+="<li class='"+prePageClass+"' page-data='1' page-rel='firstpage'>首页</li>";
        appendStr+="<li class='"+prePageClass+"' page-data='"+prePage+"' page-rel='prepage'>&lt;上一页</li>";
        var miniPageNumber = 1;
        if(currentPage-parseInt(page.maxshowpageitem/2)>0&&currentPage+parseInt(page.maxshowpageitem/2)<=pageCount){
            miniPageNumber = currentPage-parseInt(page.maxshowpageitem/2);
        }else if(currentPage-parseInt(page.maxshowpageitem/2)>0&&currentPage+parseInt(page.maxshowpageitem/2)>pageCount){
            miniPageNumber = pageCount-page.maxshowpageitem+1;
            if(miniPageNumber<=0){
                miniPageNumber=1;
            }
        }
        var showPageNum = parseInt(page.maxshowpageitem);
        if(pageCount<showPageNum){
            showPageNum = pageCount
        }
        for(var i=0;i<showPageNum;i++){
            var pageNumber = miniPageNumber++;
            var itemPageClass = "pageItem";
            if(pageNumber==currentPage){
                itemPageClass = "pageItemActive";
            }

            appendStr+="<li class='"+itemPageClass+"' page-data='"+pageNumber+"' page-rel='itempage'>"+pageNumber+"</li>";
        }
        appendStr+="<li class='"+nextPageClass+"' page-data='"+nextPage+"' page-rel='nextpage'>下一页&gt;</li>";
        appendStr+="<li class='"+nextPageClass+"' page-data='"+pageCount+"' page-rel='lastpage'>尾页</li>";
        return appendStr;

    }
}



function tt(dd){
		//alert(dd);
    }
var GG = {
    "kk":function(mm){
    	//alert(dd);
    }
}











//------------------------------------------评价星星

jQuery.fn.rater	= function(options) {

    // 默认参数
    var settings = {
        enabled	: true,
        url		: '',
        method	: 'post',
        min		: 1,
        max		: 5,
        step	: 1,
        value	: null,
        after_click	: null,
        before_ajax	: null,
        after_ajax	: null,
        title_format	: null,
        info_format	: null,
        image	: 'images/stars.jpg',
        imageAll :'images/stars-all.gif',
        defaultTips :true,
        clickTips :true,
        width	: 24,
        height	: 25
    };

    // 自定义参数
    if(options) {
        jQuery.extend(settings, options);
    }

    //外容器
    var container = jQuery(this);

    // 主容器
    var content	= jQuery('<ul class="rater-star" style="width:120px !important; "></ul>');
    content.css('background-image' , 'url(' + settings.image + ')');
    content.css('height' , settings.height);
    content.css('width' , (settings.width*settings.step) * (settings.max-settings.min+settings.step)/settings.step+'!important');
    //显示结果区域
    var result= jQuery('<div class="rater-star-result"></div>');
    container.after(result);
    //显示点击提示
    var clickTips= jQuery('<div class="rater-click-tips"><span>点击星星就可以评分了</span></div>');
    if(!settings.clickTips){
        clickTips.hide();
    }
    container.after(clickTips);
    //默认手形提示
    var tipsItem= jQuery('<li class="rater-star-item-tips" ></li>');
    tipsItem.css('width' , (settings.width*settings.step) * (settings.max-settings.min+settings.step)/settings.step);
    tipsItem.css('z-index' , settings.max / settings.step + 2);
    tipsItem.css('height','40');
    if(!settings.defaultTips){	//隐藏默认的提示
        tipsItem.hide();
    }
    content.append(tipsItem);
    // 当前选中的
    var item = jQuery('<li class="rater-star-item-current"></li>');
    item.css('background-image' , 'url(' + settings.image + ')');
    item.css('height' , settings.height);
    item.css('width' , 0);
    item.css('z-index' , settings.max / settings.step + 1);
    if (settings.value) {
        item.css('width' , ((settings.value-settings.min)/settings.step+1)*settings.step*settings.width);
    };
    content.append(item);





    // 星星
    for (var value=settings.min ; value<=settings.max ; value+=settings.step) {
        item	= jQuery('<li class="rater-star-item"><div class="popinfo"></div></li>');
        if (typeof settings.info_format == 'function') {
            //item.attr('title' , settings.title_format(value));
            item.find(".popinfo").html(settings.info_format(value));
            item.find(".popinfo").css("left",(value-1)*settings.width)
        }
        else {
            item.attr('title' , value);
        }
        item.css('height' , settings.height);
        item.css('width' , (value-settings.min+settings.step)*settings.width);
        item.css('z-index' , (settings.max - value) / settings.step + 1);
        item.css('background-image' , 'url(' + settings.image + ')');

        if (!settings.enabled) {	// 若是不能更改，则隐藏
            item.hide();
        }

        content.append(item);
    }

    content.mouseover(function(){
        if (settings.enabled) {
            jQuery(this).find('.rater-star-item-current').hide();
        }
    }).mouseout(function(){
        jQuery(this).find('.rater-star-item-current').show();
    })
    // 添加鼠标悬停/点击事件
    var shappyWidth=(settings.max-2)*settings.width;
    var happyWidth=(settings.max-1)*settings.width;
    var fullWidth=settings.max*settings.width;
    content.find('.rater-star-item').mouseover(function() {
        jQuery(this).prevAll('.rater-star-item-tips').hide();
        jQuery(this).attr('class' , 'rater-star-item-hover');
        jQuery(this).find(".popinfo").show();

        //当3分时用笑脸表示
        if(parseInt(jQuery(this).css("width"))==shappyWidth){
            jQuery(this).addClass('rater-star-happy');
        }
        //当4分时用笑脸表示
        if(parseInt(jQuery(this).css("width"))==happyWidth){
            jQuery(this).addClass('rater-star-happy');
        }
        //当5分时用笑脸表示
        if(parseInt(jQuery(this).css("width"))==fullWidth){
            jQuery(this).removeClass('rater-star-item-hover');
            jQuery(this).css('background-image' , 'url(' + settings.imageAll + ')');
            jQuery(this).css({cursor:'pointer',position:'absolute',left:'0',top:'0'});
        }
    }).mouseout(function() {
        var outObj=jQuery(this);
        outObj.css('background-image' , 'url(' + settings.image + ')');
        outObj.attr('class' , 'rater-star-item');
        outObj.find(".popinfo").hide();
        outObj.removeClass('rater-star-happy');
        jQuery(this).prevAll('.rater-star-item-tips').show();
        //var startTip=function () {
        //outObj.prevAll('.rater-star-item-tips').show();
        //};
        //startTip();
    }).click(function() {
        //jQuery(this).prevAll('.rater-star-item-tips').css('display','none');
        jQuery(this).parents(".rater-star").find(".rater-star-item-tips").remove();
        jQuery(this).parents(".goods-comm-stars").find(".rater-click-tips").remove();
        jQuery(this).prevAll('.rater-star-item-current').css('width' , jQuery(this).width());
        if(parseInt(jQuery(this).prevAll('.rater-star-item-current').css("width"))==happyWidth||parseInt(jQuery(this).prevAll('.rater-star-item-current').css("width"))==shappyWidth){
            jQuery(this).prevAll('.rater-star-item-current').addClass('rater-star-happy');
        }
        else{
            jQuery(this).prevAll('.rater-star-item-current').removeClass('rater-star-happy');
        }
        if(parseInt(jQuery(this).prevAll('.rater-star-item-current').css("width"))==fullWidth){
            jQuery(this).prevAll('.rater-star-item-current').addClass('rater-star-full');
        }
        else{
            jQuery(this).prevAll('.rater-star-item-current').removeClass('rater-star-full');
        }
        var star_count		= (settings.max - settings.min) + settings.step;
        var current_number	= jQuery(this).prevAll('.rater-star-item').size()+1;
        var current_value	= settings.min + (current_number - 1) * settings.step;

        //显示当前分值
        if (typeof settings.title_format == 'function') {
            jQuery(this).parents().nextAll('.rater-star-result').html(current_value+'分&nbsp;'+settings.title_format(current_value));
        }
        $("#StarNum").val(current_value);

        //jQuery(this).parents().next('.rater-star-result').html(current_value);
        //jQuery(this).unbind('mouseout',startTip)
    })

    jQuery(this).html(content);


}
// 星星打分
$(function(){
    var options	= {
        max	: 5,
        title_format	: function(value) {
            var title = '';
            switch (value) {
                case 1 :
                    title	= '很不满意';
                    break;
                case 2 :
                    title	= '不满意';
                    break;
                case 3 :
                    title	= '一般';
                    break;
                case 4 :
                    title	= '满意';
                    break;
                case 5 :
                    title	= '非常满意';
                    break;
                default :
                    title = value;
                    break;
            }
            return title;
        },
        info_format	: function(value) {
            var info = '';
            switch (value) {
                case 1 :
                    info	= '<div class="info-box">1分&nbsp;很不满意<div>质量非常差，令人失望了！</div></div>';
                    break;
                case 2 :
                    info	= '<div class="info-box">2分&nbsp;不满意<div>质量不好，不能满足要求。</div></div>';
                    break;
                case 3 :
                    info	= '<div class="info-box">3分&nbsp;一般<div>质量感觉一般。</div></div>';
                    break;
                case 4 :
                    info	= '<div class="info-box">4分&nbsp;满意<div>质量满意，符合我的期望。</div></div>';
                    break;
                case 5 :
                    info	= '<div class="info-box">5分&nbsp;非常满意<div>我很喜欢！太棒了！</div></div>';
                    break;
                default :
                    info = value;
                    break;
            }
            return info;
        }
    }
    $('#rate-comm-1').rater(options);
});


jQuery.fn.rater	= function(options1) {

    // 默认参数
    var settings = {
        enabled	: true,
        url		: '',
        method	: 'post',
        min		: 1,
        max		: 5,
        step	: 1,
        value	: null,
        after_click	: null,
        before_ajax	: null,
        after_ajax	: null,
        title_format	: null,
        info_format	: null,
        image	: 'images/stars.jpg',
        imageAll :'images/stars-all.gif',
        defaultTips :true,
        clickTips :true,
        width	: 24,
        height	: 25
    };

    // 自定义参数
    if(options1) {
        jQuery.extend(settings, options1);
    }

    //外容器
    var container	= jQuery(this);

    // 主容器
    var content	= jQuery('<ul class="rater-star" style="width:120px !important; "></ul>');
    content.css('background-image' , 'url(' + settings.image + ')');
    content.css('height' , settings.height);
    content.css('width' , (settings.width*settings.step) * (settings.max-settings.min+settings.step)/settings.step+'!important');
    //显示结果区域
    var result= jQuery('<div class="rater-star-result"></div>');
    container.after(result);
    //显示点击提示
    var clickTips= jQuery('<div class="rater-click-tips"><span>点击星星就可以评分了</span></div>');
    if(!settings.clickTips){
        clickTips.hide();
    }
    container.after(clickTips);
    //默认手形提示
    var tipsItem= jQuery('<li class="rater-star-item-tips" ></li>');
    tipsItem.css('width' , (settings.width*settings.step) * (settings.max-settings.min+settings.step)/settings.step);
    tipsItem.css('z-index' , settings.max / settings.step + 2);
    tipsItem.css('height','40');
    if(!settings.defaultTips){	//隐藏默认的提示
        tipsItem.hide();
    }
    content.append(tipsItem);
    // 当前选中的
    var item	= jQuery('<li class="rater-star-item-current"></li>');
    item.css('background-image' , 'url(' + settings.image + ')');
    item.css('height' , settings.height);
    item.css('width' , 0);
    item.css('z-index' , settings.max / settings.step + 1);
    if (settings.value) {
        item.css('width' , ((settings.value-settings.min)/settings.step+1)*settings.step*settings.width);
    };
    content.append(item);


    // 星星
    for (var value=settings.min ; value<=settings.max ; value+=settings.step) {
        item	= jQuery('<li class="rater-star-item"><div class="popinfo"></div></li>');
        if (typeof settings.info_format == 'function') {
            //item.attr('title' , settings.title_format(value));
            item.find(".popinfo").html(settings.info_format(value));
            item.find(".popinfo").css("left",(value-1)*settings.width)
        }
        else {
            item.attr('title' , value);
        }
        item.css('height' , settings.height);
        item.css('width' , (value-settings.min+settings.step)*settings.width);
        item.css('z-index' , (settings.max - value) / settings.step + 1);
        item.css('background-image' , 'url(' + settings.image + ')');

        if (!settings.enabled) {	// 若是不能更改，则隐藏
            item.hide();
        }

        content.append(item);
    }

    content.mouseover(function(){
        if (settings.enabled) {
            jQuery(this).find('.rater-star-item-current').hide();
        }
    }).mouseout(function(){
        jQuery(this).find('.rater-star-item-current').show();
    })
    // 添加鼠标悬停/点击事件
    var shappyWidth=(settings.max-2)*settings.width;
    var happyWidth=(settings.max-1)*settings.width;
    var fullWidth=settings.max*settings.width;
    content.find('.rater-star-item').mouseover(function() {
        jQuery(this).prevAll('.rater-star-item-tips').hide();
        jQuery(this).attr('class' , 'rater-star-item-hover');
        jQuery(this).find(".popinfo").show();

        //当3分时用笑脸表示
        if(parseInt(jQuery(this).css("width"))==shappyWidth){
            jQuery(this).addClass('rater-star-happy');
        }
        //当4分时用笑脸表示
        if(parseInt(jQuery(this).css("width"))==happyWidth){
            jQuery(this).addClass('rater-star-happy');
        }
        //当5分时用笑脸表示
        if(parseInt(jQuery(this).css("width"))==fullWidth){
            jQuery(this).removeClass('rater-star-item-hover');
            jQuery(this).css('background-image' , 'url(' + settings.imageAll + ')');
            jQuery(this).css({cursor:'pointer',position:'absolute',left:'0',top:'0'});
        }
    }).mouseout(function() {
        var outObj=jQuery(this);
        outObj.css('background-image' , 'url(' + settings.image + ')');
        outObj.attr('class' , 'rater-star-item');
        outObj.find(".popinfo").hide();
        outObj.removeClass('rater-star-happy');
        jQuery(this).prevAll('.rater-star-item-tips').show();
        //var startTip=function () {
        //outObj.prevAll('.rater-star-item-tips').show();
        //};
        //startTip();
    }).click(function(e) {
        //jQuery(this).prevAll('.rater-star-item-tips').css('display','none');
        jQuery(this).parents(".rater-star").find(".rater-star-item-tips").remove();
        jQuery(this).parents(".goods-comm-stars1").find(".rater-click-tips").remove();
        jQuery(this).prevAll('.rater-star-item-current').css('width' , jQuery(this).width());
        if(parseInt(jQuery(this).prevAll('.rater-star-item-current').css("width"))==happyWidth||parseInt(jQuery(this).prevAll('.rater-star-item-current').css("width"))==shappyWidth){
            jQuery(this).prevAll('.rater-star-item-current').addClass('rater-star-happy');
        }
        else{
            jQuery(this).prevAll('.rater-star-item-current').removeClass('rater-star-happy');
        }
        if(parseInt(jQuery(this).prevAll('.rater-star-item-current').css("width"))==fullWidth){
            jQuery(this).prevAll('.rater-star-item-current').addClass('rater-star-full');
        }
        else{
            jQuery(this).prevAll('.rater-star-item-current').removeClass('rater-star-full');
        }
        var star_count		= (settings.max - settings.min) + settings.step;
        var current_number	= jQuery(this).prevAll('.rater-star-item').size()+1;
        var current_value	= settings.min + (current_number - 1) * settings.step;

        //显示当前分值
        if (typeof settings.title_format == 'function') {
            jQuery(this).parents().nextAll('.rater-star-result').html(current_value+'分&nbsp;'+settings.title_format(current_value));
        }
        $("#StarNum").val(current_value);
        //jQuery(this).parents().next('.rater-star-result').html(current_value);
        //jQuery(this).unbind('mouseout',startTip)
        
        //取值
        console.log(current_value);
        // console.log(item.length);

                $(document).ready(function(){
                        $(".rater-star li").each(function(n){
                            var img_pic = "";
                            if (n=current_value) {
                                img_pic = 'images/stars-all.jpg';
                            }
                            var html = "";
                            var rel = "";
                         for (var i = 0 ; i < 5; i++) {
                             //Things[i]
                         }

                        });
                      });
        })





    jQuery(this).html(content);

}

$(function(){
    var options1 = {
        max	: 5,
        title_format	: function(value) {
            var title = '';
            switch (value) {
                case 1 :
                    title	= '很不满意';
                    break;
                case 2 :
                    title	= '不满意';
                    break;
                case 3 :
                    title	= '一般';
                    break;
                case 4 :
                    title	= '满意';
                    break;
                case 5 :
                    title	= '非常满意';
                    break;
                default :
                    title = value;
                    break;
            }
            return title;
        },
        info_format	: function(value) {
            var info = '';
            switch (value) {
                case 1 :
                    info	= '<div class="info-box">1分&nbsp;很不满意<div> 使用差，太令人失望了！</div></div>';
                    break;
                case 2 :
                    info	= '<div class="info-box">2分&nbsp;不满意<div>使用不好，不能满足要求。</div></div>';
                    break;
                case 3 :
                    info	= '<div class="info-box">3分&nbsp;一般<div>商品使用感觉一般。</div></div>';
                    break;
                case 4 :
                    info	= '<div class="info-box">4分&nbsp;满意<div>使用满意，符合我的期望。</div></div>';
                    break;
                case 5 :
                    info	= '<div class="info-box">5分&nbsp;非常满意<div>我很喜欢！太棒了！</div></div>';
                    break;
                default :
                    info = value;
                    break;
            }
            return info;
        }
    }
    $('#rate-comm-2').rater(options1);
});

